import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import { registerMicroApps, start } from 'qiankun'

Vue.config.productionTip = false

function genActiveRule (routerPrefix) {
  return location => location.href.split('#')[1].startsWith(routerPrefix)
}

const apps = [
  {
    name: 'wedding-order',
    entry: process.env.NODE_ENV === 'development' ? `//${ location.hostname }:20002` : ``,
    container: '#frame',
    activeRule: genActiveRule('/wedding-order'),
    loader: loadStatus => {
    },
  },
]

registerMicroApps(apps, {
  // 挂载前回调
  beforeLoad: (app) => {
    console.log('加载前回调')
  },
  // 挂载后回调
  beforeMount: app => {
    console.log('挂载之前回调')
  },
  afterMount: app => {
    console.log('挂在完成回调')
  },
  // 卸载后回调
  afterUnmount: app => {
    console.log('卸载后回调')
  }
})
start()

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#main-app')
